<?php

namespace IDock\Insurance\JTIC\Response;

use IDock\Http\Response;
use IDock\Insurance\JTIC\Response\AllJTICResponse;
use IDock\Printer\PremiumUnderwritingPrinter;

class UnderwritingResponse extends AllJTICResponse
{

    /**
     * @var PremiumUnderwritingPrinter $printer
     */
    public $printer = PremiumUnderwritingPrinter::class;

    public function printerInit(): Response
    {

        $data = $this->getBody();
        $errorCode = $data['InterfaceMsg']['ErrorCode'] ?? [];
        if($errorCode != '0000'){
            $this->setError($data['InterfaceMsg']['ErrorMessage']);
            return $this;
        }
        $code = $data['BasePart']['UndrResult'] ?? '';

        $this->printer->inquiryNo = $data['BasePart']['CarApplyNo'] ?? '';
        $this->printer->messageTip = $data['BasePart']['UndrOpinion'] ?? '';

        //下发
        if ($code == 'A2' or !$code or $code == 'C2') {
            $this->printer->statusCode = 'U2';
        }
        //成功
        if ($code == 'A1')  {
            $this->printer->statusCode = 'U1';
        }
        //人工
        if ($code == 'B1') {
            $this->printer->statusCode = 'U3';
        }

        return $this;
    }
}
